 
package com.xbongbong.admin.model.impl;

import com.xbongbong.admin.domain.dao.RaidersProductDao;
import com.xbongbong.admin.domain.entity.RaidersProductEntity;
import com.xbongbong.admin.model.RaidersProductModel;
import com.xbongbong.paas.toolbox.util.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


/**
* @author autoGen
* @time 2019-09-18 13:56:16
*/
@Service("raidersProductModel")
public class RaidersProductModelImpl implements RaidersProductModel {

	@Resource
	private RaidersProductDao dao;
	@Override
	public Integer insert(RaidersProductEntity entity){
		long now = DateUtil.getInt();
		entity.setAddTime(now);
		entity.setUpdateTime(now);
		
		return dao.insert(entity);
	}
	@Override
	public Integer update(RaidersProductEntity entity){
		long now = DateUtil.getInt();
		entity.setUpdateTime(now);
		
		return dao.update(entity);
	}

	@Override
	public Integer save(RaidersProductEntity entity){
		
		if(entity.getId() == null || Objects.equals(0L, entity.getId())) {
			return insert(entity);
		}
		return update(entity);
	}

	@Override
	public void insertBatch(List<RaidersProductEntity> entityList) {
    	dao.insertBatch(entityList);
    }

	@Override
	public Integer deleteByKey( Long key){
		return dao.deleteByKey(key);
	}

	@Override
	public RaidersProductEntity getByKey(Long key){
		return dao.getByKey(key);
	}

	@Override
	public List<RaidersProductEntity> findEntitys(Map<String ,Object>  param){
		return dao.findEntitys(param);
	}

    @Override
	public Integer getEntitysCount(Map<String ,Object>  param){
		return dao.getEntitysCount(param);
	}

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
	public Map<Long, RaidersProductEntity> getProductIdEntityMap(Collection<Long> productIdIn) {
		if (productIdIn == null || productIdIn.size() < 1) {
			return new HashMap<>(1);
		}
		Map<String, Object> productParam = new HashMap<>(1);
		productParam.put("productIdIn", productIdIn);
		List<RaidersProductEntity> productList = findEntitys(productParam);
		Map<Long, RaidersProductEntity> productIdEntityMap = new HashMap<>(productList.size());
		for (RaidersProductEntity product : productList) {
			Long productId = product.getId();
			productIdEntityMap.put(productId, product);
		}
		return productIdEntityMap;
	}


}

 